package com.zzr.zzrbackend.controller;

import com.zzr.zzrbackend.pojo.dto.CommonResult;
import com.zzr.zzrbackend.pojo.dto.param.*;
import com.zzr.zzrbackend.pojo.dto.result.*;
import com.zzr.zzrbackend.service.LoginService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.security.NoSuchAlgorithmException;

@RestController
public class LoginController {
    @Resource
    LoginService loginService;
    @Resource
    private HttpServletRequest httpServletRequest;
    @Resource
    private HttpServletResponse httpServletResponse;

    //登陆接口
    @PostMapping("/api/login/c")
    public CommonResult<LoginResult> login(@Validated @RequestBody LoginParam loginParam) throws NoSuchAlgorithmException {
        return loginService.login(loginParam, httpServletRequest, httpServletResponse);
    }

    @PostMapping("/api/login/c-new")
    public CommonResult<LoginResult> login(@RequestBody String param) throws Exception {
        return loginService.loginNew(param);
    }

    @PostMapping("/api/register")
    public CommonResult<NoData> register(@Validated @RequestBody RegisterParam registerParam) throws NoSuchAlgorithmException {
        return loginService.register(registerParam);
    }

    @PostMapping("/api/verify-phone")
    public CommonResult<NoData> verifyPhone(@Validated @RequestBody SeedCodeParam seedCodeParam) throws NoSuchAlgorithmException {
        return loginService.verifyPhone(seedCodeParam);
    }

    @PostMapping("/api/set-identity")
    public CommonResult<SetIdentityResult> setIdentity(@Validated @RequestBody SetIdentityParam SetIdentityParam) {
        return loginService.setIdentity(SetIdentityParam);
    }

    @PostMapping("/api/set-child-information/")
    public CommonResult<NoData> setChildInformation(@Validated @RequestBody ChildInformationParam childInformationParam) {
        return loginService.setChildInformation(childInformationParam);
    }

    @PostMapping("/api/set-parent-information/")
    public CommonResult<NoData> setParentInformation(@Validated @RequestBody ParentInformationParam parentInformationParam) {
        return loginService.setParentInformation(parentInformationParam);
    }

    @PostMapping("/api/get/invitation-code/")
    public CommonResult<GetInvitationCodeResult> getInvitationCode() {
        return loginService.getInvitationCode();
    }

    @PostMapping("/api/attend/invitation-code/")
    public CommonResult<NoData> setInvitationCode(@Validated @RequestBody InvitationCode invitationCode) {
        return loginService.setInvitationCode(invitationCode);
    }

    @PostMapping("/api/verify/invitation-code/")
    public CommonResult<VerifyInvitationCodeResult> verifyInvitationCode() {
        return loginService.verifyInvitationCode();
    }

    @PostMapping("/api/find-password")
    public CommonResult<NoData> findPassword(@Validated @RequestBody FindPasswordParam findPasswordParam)throws NoSuchAlgorithmException{
        return loginService.findPassword(findPasswordParam);
    }
}
